﻿using System;
using System.Collections.Generic;
using SCG.SolarVengeanceEngine;
using SCG.General;

namespace SCG.SolarVengeance.Scenarios
{
    public class GalacticCenter : Scenario
    {
        //start with some good resources, players will need it!
        public override int DefaultCapitalResources
        {
            get
            {
                return 200;
            }
        }

        //scenario build logic
        public override void BuildScenario(int numPlayers, int capitalValues, int startingResources)
        {
            //Create the StarSystems along the borders
            int numSystems = Random(18, 24);
            for (int edge = 0; edge < numSystems; edge++)
            {
                SCGPoint pt = GetEdgePoint();
                int value = (Random(1, 20) + Random(1, 20) + Random(1, 20)) / 3;
                int shields = Random(0, (int)(value * 1.5));
                int scanners = Random(0, (int)(value * 1.5));
                CreateStarSystem((int)pt.X, (int)pt.Y, value, shields, scanners, Random(0, 5));
            }

            //Assign capitals to these StarSystems
            foreach (Player p in Game.Players)
                AssignCapital(p, new SCGRect(0, 0, 99, 99));

            //place some nebulae in the center
            for (int numNeb = 0; numNeb < 4; numNeb++)
            {
                int nx = Random(30, 70);
                int ny = Random(30, 70);
                CreateNebula(nx, ny, Random(1, 4), Random(10, 100));
            }

            //sprinkle some wormholes around the edges, leading in
            for (int w = 0; w < 10; w++)
            {
                SCGPoint ptW = GetEdgePoint();
                CreateWormhole((int)ptW.X, (int)ptW.Y, Random(40, 60), Random(40, 40));
            }

            //Create the central cluster
            CreateStarCluster(Random(8, 16), 50, 50, 50, 50, 20, 5);

            //Give central cluster stars many resources
            for(int i = numSystems; i < Game.StarSystems.Count; i++)
            {
                StarSystem sys = Game.StarSystems[i];
                sys.Resources = Random(100, 300);
            }

            //Place the supermassive black hole
            int bhx = Random(40, 60);
            int bhy = Random(40, 60);
            CreateBlackHole(bhx, bhy, Random(20, 25));
        }

        //description
        public override string Description
        {
            get
            {
                return "The StarSystems near the Galactic Center are very rich in Resources.  However, a Super-Massive Black Hole " +
                    "lurks somewhere near the Center.  Resource-starved warring Star Lords brave the risk to try and gain the upper " +
                    "hand on their enemies once and for all.";
            }
        }

        //Get a point within one of the 4 edges
        private SCGPoint GetEdgePoint()
        {
            int x1;
            int y1;
            int x2;
            int y2;
            switch (Random(1, 4))
            {
                case 1:
                    x1 = 0;
                    y1 = 0;
                    x2 = Game.Width - 1;
                    y2 = 19;
                    break;
                case 2:
                    x1 = Game.Width - 20;
                    y1 = 0;
                    x2 = Game.Width - 1;
                    y2 = Game.Height - 1;
                    break;
                case 3:
                    x1 = 0;
                    y1 = Game.Height - 20;
                    x2 = Game.Width - 1;
                    y2 = Game.Height - 1;
                    break;
                default:
                    x1 = 0;
                    y1 = 0;
                    x2 = 19;
                    y2 = Game.Height - 20;
                    break;            
            }
            return new SCGPoint(Random(x1, x2), Random(y1, y2));
        }
    }
}
